package com.yuncheng.oaApi.busService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.oaApi.FlowController.*;
import com.yuncheng.oaApi.constant.OaFlowConstant;
import com.yuncheng.oaApi.entity.OaProcessBusiness;
import com.yuncheng.oaApi.entity.OaJobEntity;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.oaApi.service.IOaProcessBusinessService;
import com.yuncheng.oaApi.service.IOaSpcySqsxJobService;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.oaApi.vo.OaReturnVo;
import com.yuncheng.oaApi.vo.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component(value = "ReturnZdyService")
public class ReturnZdyService {
    @Resource
    @Lazy
    private NewOaLgqsFlowController newOaLgqsFlowController;

    @Resource
    @Lazy
    private NewOaBgypglFlowController newOaBgypglFlowController;

    @Resource
    @Lazy
    private NewOaHysglFlowController newOaHysglFlowController;

    @Resource
    @Lazy
    private NewOaJbzbFlowController newOaJbzbFlowController;

    @Resource
    @Lazy
    private NewOaQxjspFlowController newOaQxjspFlowController;

    @Resource
    @Lazy
    private NewOaXcxxspglFlowController newOaXcxxspglFlowController;

    @Resource
    @Lazy
    private NewOaXzswspFlowController newOaXzswspFlowController;

    @Resource
    @Lazy
    private NewNkRsHtspjlFlowController newNkRsHtspjlFlowController;



    @Resource
    @Lazy
    private IOaProcessBusinessService oaProcessBusinessService;

    @Resource
    @Lazy
    private IOaSpcySqsxJobService spcySqsxJobService;

    @Resource
    @Lazy
    private NewNkRsJcyBxFlowController newNkRsBxlcFlowController;

    @Resource
    @Lazy
    private NewNkRsCcSpFlowController nkRsCcSpFlowController;



    @Resource
    @Lazy
    private NewNkYstpsqFlowController newNkYstpsqFlowController;

    @Resource
    @Lazy
    private NewPartyRsDyrdsqjlFlowController newPartyRsDyrdsqjlFlowController;

    @Resource
    @Lazy
    private NewQyResevvationFlowController newQyResevvationFlowController;


    @Resource
    @Lazy
    private NewBxTssqsqFlowController newBxTssqFlowController;

    //部门预算申报
    @Resource
    @Lazy
    private NewNkbmyssbFlowController newNkbmyssbFlowController;

    //预算申报
    @Resource
    @Lazy
    private NewNkyssbFlowController newNkyssbFlowController;


    /**通过我的已办 直接退回 可以通过流程模板编码来指定 调用方法
     * 先调用查询：queryAllYbJob，在调用退回：returnUpperzdyFlowJob*/
    public Result getCurrentJobPrevious(String lcmbbm, String jobid) {
        HttpResult<?> httpResult = new HttpResult<>();

        if (lcmbbm.equals(OaFlowConstant.OA_LGQS)) {
            httpResult = newOaLgqsFlowController.queryAllYbJob(jobid, true);
        } else if (lcmbbm.equals(OaFlowConstant.OA_QXJ)) {
            httpResult = newOaQxjspFlowController.queryAllYbJob(jobid, true);

        } else if (lcmbbm.equals(OaFlowConstant.OA_JBZB)) {
            httpResult = newOaJbzbFlowController.queryAllYbJob(jobid, true);

        } else if (lcmbbm.equals(OaFlowConstant.OA_XZSWSP)) {
            httpResult = newOaXzswspFlowController.queryAllYbJob(jobid, true);

        } else if (lcmbbm.equals(OaFlowConstant.OA_XCXXSP)) {
            httpResult = newOaXcxxspglFlowController.queryAllYbJob(jobid, true);

        } else if (lcmbbm.equals(OaFlowConstant.OA_HYSSQGL)) {
            httpResult = newOaHysglFlowController.queryAllYbJob(jobid, true);

        } else if (lcmbbm.equals(OaFlowConstant.OA_BGYPSQ)) {
            httpResult = newOaBgypglFlowController.queryAllYbJob(jobid, true);

        } else if (lcmbbm.equals(OaFlowConstant.NK_BXSQLC)){
            httpResult = newNkRsBxlcFlowController.queryAllYbJob(jobid,true);

        }else if (lcmbbm.equals(OaFlowConstant.NK_CCSP)){
            httpResult = nkRsCcSpFlowController.queryAllYbJob(jobid, true);

        }else if (lcmbbm.equals(OaFlowConstant.NK_YSTPSQ)){
            httpResult = newNkYstpsqFlowController.queryAllYbJob(jobid,true);

        }else if (lcmbbm.equals(OaFlowConstant.FZPARTYWORKFLOW)){
            httpResult = newPartyRsDyrdsqjlFlowController.queryAllYbJob(jobid,true);
        }else if (lcmbbm.equals(OaFlowConstant.QY_YYZXDJ)){
            httpResult = newQyResevvationFlowController.queryAllYbJob(jobid, true);
        }else if (lcmbbm.equals(OaFlowConstant.NK_HTSPLC)){
            httpResult = newNkRsHtspjlFlowController.queryAllYbJob(jobid,true);
        }else if (lcmbbm.equals(OaFlowConstant.BXD_TSSXSQ)){
            httpResult = newBxTssqFlowController.queryAllYbJob(jobid,true);
        }else if (lcmbbm.equals(OaFlowConstant.NK_BM_YSSBLC)){
            httpResult = newBxTssqFlowController.queryAllYbJob(jobid,true);
        }

        return Result.ok(httpResult);
    }

    public Result returnZdJob(OaReturnVo oaReturnVo) {
        if (StringUtils.isBlank(oaReturnVo.getLcmbbm())){
            throw new BusinessException("未查询到流程模板编码,请输入编码");
        }
        HttpResult<?> httpResult = new HttpResult<>();

        if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.OA_LGQS)) {
            httpResult = newOaLgqsFlowController.returnUpperzdyFlowJob(oaReturnVo);

        } else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.OA_QXJ)) {
            httpResult = newOaQxjspFlowController.returnUpperzdyFlowJob(oaReturnVo);

        } else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.OA_JBZB)) {
            httpResult = newOaJbzbFlowController.returnUpperzdyFlowJob(oaReturnVo);

        } else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.OA_XZSWSP)) {
            httpResult = newOaXzswspFlowController.returnUpperzdyFlowJob(oaReturnVo);

        } else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.OA_XCXXSP)) {
            httpResult = newOaXcxxspglFlowController.returnUpperzdyFlowJob(oaReturnVo);

        } else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.OA_HYSSQGL)) {
            httpResult = newOaHysglFlowController.returnUpperzdyFlowJob(oaReturnVo);

        } else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.OA_BGYPSQ)) {
            httpResult = newOaBgypglFlowController.returnUpperzdyFlowJob(oaReturnVo);
        } else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.NK_BXSQLC)){
            httpResult = newNkRsBxlcFlowController.returnUpperzdyFlowJob(oaReturnVo);

        }else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.NK_CCSP)){
            httpResult = nkRsCcSpFlowController.returnUpperzdyFlowJob(oaReturnVo);

        }else  if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.NK_YSTPSQ)){
            httpResult = newNkYstpsqFlowController.returnUpperzdyFlowJob(oaReturnVo);
        }else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.FZPARTYWORKFLOW)){
            httpResult = newPartyRsDyrdsqjlFlowController.returnUpperzdyFlowJob(oaReturnVo);
        }else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.QY_YYZXDJ)){
            httpResult = newQyResevvationFlowController.returnUpperzdyFlowJob(oaReturnVo);
        }else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.NK_HTSPLC)){
            httpResult = newNkRsHtspjlFlowController.returnUpperzdyFlowJob(oaReturnVo);
        }else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.BXD_TSSXSQ)){
            httpResult = newBxTssqFlowController.returnUpperzdyFlowJob(oaReturnVo);
        }else if (oaReturnVo.getLcmbbm().equals(OaFlowConstant.NK_BM_YSSBLC)){
            httpResult = newBxTssqFlowController.returnUpperzdyFlowJob(oaReturnVo);
        }

        List<OaJobEntity> oaJobEntityList = spcySqsxJobService.list(new LambdaQueryWrapper<OaJobEntity>().eq(OaJobEntity::getId, oaReturnVo.getJobid()));
        String fpid = oaJobEntityList.get(0).getFpid();
        List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>().eq(OaProcessBusiness::getFpid, fpid));
        String oaproId = oaProcessBusinessList.get(0).getId();
        OaProcessBusiness processBusiness = oaProcessBusinessService.getById(oaproId);
        processBusiness.setFsfkch(1);
        oaProcessBusinessService.updateById(processBusiness);
        return Result.ok(httpResult);
    }

}
